//
//  NRWSingleChooseCell.m
//  NRWMall
//
//  Created by 邢毅 on 2018/6/7.
//  Copyright © 2018年 com.anpxd. All rights reserved.
//

#import "NRWSingleChooseCell.h"

@implementation NRWSingleChooseCell
{
    UILabel *_mTitleLabel;
    UIImageView *_mSelectImageView;
}

- (void)setTitle:(NSString *)title {
    
    _title = title;
    
    _mTitleLabel.text = title;
}

- (void)setDidSelect:(BOOL)didSelect {
    
    _didSelect = didSelect;
    
    _mSelectImageView.hidden = !didSelect;
    
    _mTitleLabel.textColor = didSelect? mainColor(): mainFontColor();
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupUI];
        
        [self layoutUI];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsZero;
    }
    return self;
}

- (void)setupUI {
    
    _mTitleLabel = [[UILabel alloc] init];
    _mTitleLabel.font = getThemeFont(14);
    [self.contentView addSubview:_mTitleLabel];
    
    _mSelectImageView = [[UIImageView alloc] init];
    _mSelectImageView.backgroundColor = [UIColor whiteColor];
    _mSelectImageView.opaque = YES;
    _mSelectImageView.image = getImage(@"img_select");
    _mSelectImageView.hidden = YES;
    [self.contentView addSubview:_mSelectImageView];
}

- (void)layoutUI {
    
    [_mTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(16);
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
    
    [_mSelectImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-19);
        make.centerY.equalTo(self.contentView.mas_centerY);
    }];
}

@end
